import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
/*
 * 首页轮播图组件
 */
class SwiperBanner extends StatelessWidget {
  final List swiperDataList;

  SwiperBanner({Key key, this.swiperDataList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    //初始化屏幕适配
    ScreenUtil.init(context,width: 750,height: 1334);
    return Container(
      width: ScreenUtil().setWidth(750),
      height: ScreenUtil().setHeight(300),
      child: Swiper(
        //构造器
        itemBuilder: (BuildContext context, int index) {
          return ConstrainedBox(
            constraints: new BoxConstraints.expand(),
            child: Image.network(
              "${swiperDataList[index]['image']}",
              fit: BoxFit.fitWidth,
            ),
          );
        },
        //轮播图数量
        itemCount: swiperDataList.length,
        //是否有指示器
        pagination: SwiperPagination(),
        //是否轮播
        autoplay: true,
        //点击事件
        onTap: (index) {},
        //相邻子条目视窗比例
        viewportFraction: 1,
        //用户进行操作时停止自动翻页
        autoplayDisableOnInteraction: true,
        //无线轮播
        loop: true,
        //当前条目缩放比例
        scale: 1 ,
      ),
    );
  }
}
